#ifndef GY_REFLECTIONCLASS_H
#define GY_REFLECTIONCLASS_H

#include <QObject>
#include <QByteArray>
#include <QMetaObject>
#include <QHash>

class GY_ReflectionClass
{
public:
    template<typename T> void registerClass()
    {
        m_Instance.insert(T::staticMetaObject.className(), T::staticMetaObject);
    }

    template<typename T> void registerClass(const QString& typeName)
    {
        if(!m_Maping.keys().contains(T::staticMetaObject.className()))
        {
            m_Maping.insert(T::staticMetaObject.className(),QVector<QByteArray>()<<typeName.toLatin1());
        }
        m_Maping[T::staticMetaObject.className()]<<T::staticMetaObject.className();
        m_Instance.insert(typeName.toLatin1(),T::staticMetaObject);
    }

    QObject* newInstance( const QByteArray& className,
                                 QGenericArgument val0 = QGenericArgument(nullptr),
                                 QGenericArgument val1 = QGenericArgument(),
                                 QGenericArgument val2 = QGenericArgument(),
                                 QGenericArgument val3 = QGenericArgument(),
                                 QGenericArgument val4 = QGenericArgument(),
                                 QGenericArgument val5 = QGenericArgument(),
                                 QGenericArgument val6 = QGenericArgument(),
                                 QGenericArgument val7 = QGenericArgument(),
                                 QGenericArgument val8 = QGenericArgument(),
                                 QGenericArgument val9 = QGenericArgument() )
    {
        QObject* pObject=nullptr;
        if(m_Instance.keys().contains(className))
        {
            pObject = (QObject*)m_Instance.value(className).newInstance(val0, val1, val2, val3, val4,
                                                                           val5, val6, val7, val8, val9);
        }
        else if(m_Maping.keys().contains(className))
        {
            pObject = (QObject*)m_Instance.value(m_Maping.value(className).at(0)).newInstance(val0, val1, val2, val3, val4,
                                                                           val5, val6, val7, val8, val9);
        }
        return pObject;
    }

private:
    QHash<QByteArray, QMetaObject> m_Instance;
    QHash<QByteArray, QVector<QByteArray>> m_Maping;
};

#endif // GY_REFLECTIONCLASS_H
